using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Lexalytics;

namespace SalienceEngineDemo
{
    public partial class ctrlGetSummary : UserControl, DemoControl
    {
        public RichTextBox oTextBox;


        public ctrlGetSummary(RichTextBox oTextBox)
        {
            InitializeComponent();
            this.oTextBox = oTextBox;
            EnableProcessButton();
        }

        private void getSummary_VisibleChanged(object sender, EventArgs e)
        {
            rtbResults.Text = "";
        }

        private void btnProcess_Click(object sender, EventArgs e)
        {
            processText();
        }

        public void processText()
        {
            try
            {
                SalienceDemo.oSalienceSession.PrepareText(this.oTextBox.Text);
                rtbResults.Text = SalienceDemo.oSalienceSession.GetSummary(Convert.ToInt32(SalienceDemo.oConfig.activeSettings().settings["SummaryLength"]));
                rtbActions.Text = "";
                SalienceDocumentDetails oDetails = SalienceDemo.oSalienceSession.GetDocumentDetails();
                foreach (SalienceSentence Sentence in oDetails.Sentences)
                {
                    if(Sentence.nImperative != 0)
                    {
                        rtbActions.Text += Sentence.sText + "\n";
                    }
                }
            }
            catch (SalienceException e)
            {
                MessageBox.Show(e.Message, "Salience Demo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

        }

        #region DemoControl interface methods
        public void btnOptions_Click(object sender, EventArgs e)
        {
            ((SalienceDemo)this.Parent).StartOptionsDialog((int)Dialogs.Options.OptionSections.DOCUMENTS);
            EnableProcessButton();
        }

        public void SetFontSize()
        {
            this.rtbActions.Font = new Font(this.oTextBox.Font.FontFamily, Properties.Settings.Default.fFontSize);
            this.rtbResults.Font = new Font(this.oTextBox.Font.FontFamily, Properties.Settings.Default.fFontSize);
        }

        public void EnableProcessButton()
        {
            this.btnProcess.Enabled = (oTextBox.Text.Trim().Length > 0);
        }

        #endregion
    }
}
